//
//  PaymentViewController.m
//  shanHaiHuiApp
//
//  Created by 小和尚 on 2018/3/10.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "PaymentViewController.h"
#import "PaymentTableViewCell.h"
#import "InputMoneyTableViewCell.h"
#import "PayMoneyTableViewCell.h"
#import "GoodMoneyTableViewCell.h"
#import "CardView.h"
#import "PaymentSuccessViewController.h"
#import "PayMoneyWithOutTableViewCell.h"

#import "ChooseNumView.h"


//配送的view
#import "DispatchStyleView.h"

//商品属性
#import "PayMentGoodModel.h"

//商品批号
#import "PayMentSpphModel.h"




@interface PaymentViewController ()<UITableViewDelegate,UITableViewDataSource>


Strong UITableView * tableView;
Strong NSMutableArray * contentArr;


//底部购物车视图
Strong UIView * bottomView;
Strong UIImageView * shopImageview;
Strong UILabel * totalPriceLabel;
//销量:
Strong UILabel * numberLabel;
Strong UILabel * countLabel;
Strong UIButton * payBtn;

//保存点了哪一行

Assign NSInteger indexRow;

//会员卡密码
Strong NSString * textStrPass;

//会员卡支付
Strong NSString *memberPay;

//会员卡余额

Strong NSString * memberMoney;

//需支付金额
Strong NSString * needPayMoney;

//还需支付金额
Strong NSString * orderCashAll;

//找零
Strong NSString * orderCashChange;

//选中了哪个一个按钮,跳页面

Strong NSString * index;

//商品批号比较

Strong NSString * strGood;
Strong NSString * strSpph;

// 配送类型
Strong NSString * disttype;

//收货人
Strong NSString * personText;

//联系方式
Strong NSString * contactText;

//配送地址

Strong NSString * dispatchText;

//配送备注

Strong NSString * remarkText;

//门店地址
Strong NSString * shopAdress;

//门店编号
Strong NSString * shopFid;

//做一个字典,保存cell点击了哪一行和他的高度

Strong NSMutableDictionary * indexHeight;

Strong NSString * height;
Strong NSIndexPath * indexPath;

Strong NSDictionary *parameters;

//支付成功后返回的订单编号和token
Strong NSString * orderNo;
Strong NSString * tokenSuccess;

//修改商品批号数组
Strong NSMutableArray * changeSpphArr;

Strong InputMoneyTableViewCell * inputCell;

Strong PayMoneyTableViewCell * cellPayMoney;

@end

//网络
@implementation PaymentViewController (NetWorking)

//商品批号接口
- (void)getSerialNumDataWith:(NSString *)spph{
    [self showprogressHUD];
    
    NSDictionary *parameters = @{
                                 @"spbh":spph
                                 
                                 }.mutableCopy;
    
    [self.changeSpphArr removeAllObjects];
    [[AFAppDotNetAPIClient sharedClient] POST:@"mspphList.do" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        
        if ([responseObject[@"code"] integerValue] == 0) {
            
            for (NSDictionary * dic in responseObject[@"spphList"]) {
                PayMentSpphModel * model = [[PayMentSpphModel alloc] init];
                [model payMentSpphModelWithDic:dic];
                [self.changeSpphArr addObject:model];
            }
            
            NSLog(@"000000%@",self.changeSpphArr);
            ChooseNumView * chooseView = [[ChooseNumView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
            [chooseView show];
            chooseView.chooseArr = self.changeSpphArr;
            chooseView.count = self.orderArr.count;
        }else{
            ShowMessage(responseObject[@"msg"]);
        }
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

//提交订单接口
- (void)getMorderPayCheckData{
    [self showprogressHUD];
    NSDictionary *parameters = @{
                                 @"orgid":[UserModel sharedInstanced].fid,
                                 @"userid":[UserModel sharedInstanced].userID,
                                 @"cardno":self.orderDic[@"fCardno"],
                                 @"cardid":self.orderDic[@"fCardid"],
                                 @"cardpassword":self.textStrPass,
                                 @"orderCardPay":[NSString stringWithFormat:@"%@",self.orderDic[@"fCardMoney"]]
                                 }.mutableCopy;
     NSLog(@"%@",parameters);
    
    [[AFAppDotNetAPIClient sharedClient] POST:@"morderPayCheck.do" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
       
        if ([responseObject[@"code"] integerValue] == 0) {
            self.orderNo = responseObject[@"orderNo"];
           
        }else{
            ShowMessage(responseObject[@"msg"]);
            
        }
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

// 将数组转JSON
- (NSData *)toJSONData:(id)theData{
    
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:theData
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if ([jsonData length] > 0 && error == nil){
        return jsonData;
    }else{
        return nil;
    }
}

//确认支付接口
//默认的时候选第一个
- (void)getConfigSaleDataWithIndex{
    [self showprogressHUD];
    
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:5];
    
    NSString * str = nil;
    for (PayMentGoodModel *model in self.orderArr) {
        NSDictionary *dic = @{@"spbh":model.spbh,
                              @"spmc":model.spmc,
                              @"xsdj":[NSString stringWithFormat:@"%@",model.xsdj],
                              @"xssl":[NSString stringWithFormat:@"%@",model.xssl],
                              @"xsje":[NSString stringWithFormat:@"%@",model.xsje]
                              };
        [arr addObject:dic];
        
        str = [[NSString alloc] initWithData:[self toJSONData:arr]
                                    encoding:NSUTF8StringEncoding];
    }
    
    NSMutableArray *arrSpph = [NSMutableArray arrayWithCapacity:5];
    
    NSString * strSpphJson = nil;
    for (PayMentSpphModel *model in self.orderSpphArr) {
        NSDictionary *dict = @{@"fSpbh":model.fSpbh,
                               @"fSite":model.fSite,
                               @"fPh":model.fPh,
                               @"fPc":model.fPc,
                               @"xssl":[NSString stringWithFormat:@"%@",model.xssl]
                               };
        [arrSpph addObject:dict];
        
        strSpphJson = [[NSString alloc] initWithData:[self toJSONData:arrSpph]
                                            encoding:NSUTF8StringEncoding];
    }
    self.parameters = @{
                        @"orgid":[UserModel sharedInstanced].fid,
                        @"userid":[UserModel sharedInstanced].userID,
                        @"cardid":self.orderDic[@"fCardid"],
                        @"cardno":self.orderDic[@"fCardno"],
                        @"cardpassword":self.textStrPass,
                        @"orderXssl":self.orderDic[@"orderXssl"],
                        @"orderXsje":self.orderDic[@"orderXsje"],
                        @"orderCardPay":[NSString stringWithFormat:@"%@",self.memberPay],
                        @"orderCashPay":self.needPayMoney,
                        @"orderCashAll":self.orderCashAll,
                        @"orderCashChange":self.orderCashChange,
                        @"token":[UserModel sharedInstanced].token,
                        @"disttype":self.disttype,
                        @"orderSps":str,
                        @"orderSpphs":strSpphJson
                        }.mutableCopy;
    [[AFAppDotNetAPIClient sharedClient] POST:@"morderPay.do" parameters:self.parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] intValue] == 0) {
            
            [UserModel sharedInstanced].token = responseObject[@"token"];
            
            [UserModel sharedInstanced].orderNo = responseObject[@"orderNo"];
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"是否确认支付"
                                                                           message:nil
                                        preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action) {
                PaymentSuccessViewController * vc = [[PaymentSuccessViewController alloc] init];
                
                vc.orderArrSuccess = self.orderArr;
                
                vc.orderDicSuccess = self.orderDic;
                
                vc.orderSpphArrSuccess = self.orderSpphArr;
                
                vc.memCardSuccess = self.memberPay;
                
                vc.payedMoneySuccess = self.memberMoney;
                
                vc.cashPaySuccess = self.orderCashAll;
                
                vc.changeMoneySuccess = self.orderCashChange;
                
                vc.orderNo =  [UserModel sharedInstanced].orderNo;
                
                vc.dispatchType = @"会员自提";
                
                [self.navigationController pushViewController:vc animated:YES];
                                                                      
                                                    }];
            UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                        handler:^(UIAlertAction * action) {
                                                                     
                                                    }];
            
            [alert addAction:defaultAction];
            [alert addAction:cancelAction];
            [self presentViewController:alert animated:YES completion:nil];
            
        }else{
            
            ShowMessage(responseObject[@"msg"]);
            [UserModel sharedInstanced].token = responseObject[@"token"];
        }
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}


//2.开始选择的某个门店的时候调用
- (void)getConfigSaleDataWithIndex:(NSString *)index{
    [self showprogressHUD];

    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:5];
    
    NSString * str = nil;
    for (PayMentGoodModel *model in self.orderArr) {
        NSDictionary *dic = @{@"spbh":model.spbh,
                              @"spmc":model.spmc,
                              @"xsdj":[NSString stringWithFormat:@"%@",model.xsdj],
                              @"xssl":[NSString stringWithFormat:@"%@",model.xssl],
                              @"xsje":[NSString stringWithFormat:@"%@",model.xsje]
                              };
        [arr addObject:dic];
        
        str = [[NSString alloc] initWithData:[self toJSONData:arr]
                                    encoding:NSUTF8StringEncoding];
    }
    
    NSMutableArray *arrSpph = [NSMutableArray arrayWithCapacity:5];
    
    NSString * strSpphJson = nil;
    for (PayMentSpphModel *model in self.orderSpphArr) {
        NSDictionary *dict = @{@"fSpbh":model.fSpbh,
                              @"fSite":model.fSite,
                              @"fPh":model.fPh,
                              @"fPc":model.fPc,
                              @"xssl":[NSString stringWithFormat:@"%@",model.xssl]
                              };
        [arrSpph addObject:dict];
        
       strSpphJson = [[NSString alloc] initWithData:[self toJSONData:arrSpph]
                                    encoding:NSUTF8StringEncoding];
    
    }
    
    if ([index isEqualToString:@"1"]) {
        NSLog(@"第一个界面");
        self.parameters = @{
                                     @"orgid":[UserModel sharedInstanced].fid,
                                     @"userid":[UserModel sharedInstanced].userID,
                                     @"cardid":self.orderDic[@"fCardid"],
                                     @"cardno":self.orderDic[@"fCardno"],
                                     @"cardpassword":self.textStrPass,
                                     @"orderXssl":self.orderDic[@"orderXssl"],
                                     @"orderXsje":self.orderDic[@"orderXsje"],
                                     @"orderCardPay":[NSString stringWithFormat:@"%@",self.memberPay],
                                     @"orderCashPay":self.needPayMoney,
                                     @"orderCashAll":self.orderCashAll,
                                     @"orderCashChange":self.orderCashChange,
                                     @"token":[UserModel sharedInstanced].token,
                                     @"disttype":self.disttype,
                                     @"orderSps":str,
                                     @"orderSpphs":strSpphJson
                                     }.mutableCopy;
    }
    
    
    if ([index isEqualToString:@"2"]) {
        NSLog(@"第er个界面");
        self.parameters = @{
                            @"orgid":[UserModel sharedInstanced].fid,
                            @"userid":[UserModel sharedInstanced].userID,
                            @"cardid":self.orderDic[@"fCardid"],
                            @"cardno":self.orderDic[@"fCardno"],
                            @"cardpassword":self.textStrPass,
                            @"orderXssl":self.orderDic[@"orderXssl"],
                            @"orderXsje":self.orderDic[@"orderXsje"],
                            @"orderCardPay":[NSString stringWithFormat:@"%@",self.memberPay],
                            @"orderCashPay":self.needPayMoney,
                            @"orderCashAll":self.orderCashAll,
                            @"orderCashChange":self.orderCashChange,
                            @"token":[UserModel sharedInstanced].token,
                            @"disttype":self.disttype,
                            @"distconsignee":self.personText,
                            @"distconsigneephone":self.contactText,
                            @"distaddress":self.dispatchText,
                            @"distremark":self.remarkText,
                            @"orderSps":str,
                            @"orderSpphs":strSpphJson
                            }.mutableCopy;
    }
    if ([index isEqualToString:@"3"]) {
        NSLog(@"第san个界面");
        self.parameters = @{
                            @"orgid":[UserModel sharedInstanced].fid,
                            @"userid":[UserModel sharedInstanced].userID,
                            @"cardid":self.orderDic[@"fCardid"],
                            @"cardno":self.orderDic[@"fCardno"],
                            @"cardpassword":self.textStrPass,
                            @"orderXssl":self.orderDic[@"orderXssl"],
                            @"orderXsje":self.orderDic[@"orderXsje"],
                            @"orderCardPay":[NSString stringWithFormat:@"%@",self.memberPay],
                            @"orderCashPay":self.needPayMoney,
                            @"orderCashAll":self.orderCashAll,
                            @"orderCashChange":self.orderCashChange,
                            @"token":[UserModel sharedInstanced].token,
                            @"disttype":self.disttype,
                            @"distorgid":[UserModel sharedInstanced].fid1,
                            //@"distaddress":self.orderDic[@"distaddress"],
                            @"distaddress":[UserModel sharedInstanced].fMemo1,
                            @"distremark":self.remarkText,
                            @"orderSps":str,
                            @"orderSpphs":strSpphJson
                            }.mutableCopy;
    }
    if ([index isEqualToString:@"4"]) {
        NSLog(@"第si个界面");
        self.parameters = @{
                            @"orgid":[UserModel sharedInstanced].fid,
                            @"userid":[UserModel sharedInstanced].userID,
                            @"cardid":self.orderDic[@"fCardid"],
                            @"cardno":self.orderDic[@"fCardno"],
                            @"cardpassword":self.textStrPass,
                            @"orderXssl":self.orderDic[@"orderXssl"],
                            @"orderXsje":self.orderDic[@"orderXsje"],
                            @"orderCardPay":[NSString stringWithFormat:@"%@",self.memberPay],
                            @"orderCashPay":self.needPayMoney,
                            @"orderCashAll":self.orderCashAll,
                            @"orderCashChange":self.orderCashChange,
                            @"token":[UserModel sharedInstanced].token,
                            @"disttype":self.disttype,
                            @"distorgid":[UserModel sharedInstanced].fid1,
                            @"distaddress":[UserModel sharedInstanced].fMemo1,
                            @"distremark":self.remarkText,
                            @"orderSps":str,
                            @"orderSpphs":strSpphJson
                            }.mutableCopy;
    }
    
    NSLog(@"987654321%@",self.parameters);
    
    [[AFAppDotNetAPIClient sharedClient] POST:@"morderPay.do" parameters:self.parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        
        NSLog(@"%@",responseObject);
        if ([responseObject[@"code"] intValue] == 0) {
            
            [UserModel sharedInstanced].token = responseObject[@"token"];
            
             [UserModel sharedInstanced].orderNo = responseObject[@"orderNo"];
           
           
            PaymentSuccessViewController * vc = [[PaymentSuccessViewController alloc] init];
            
            vc.orderArrSuccess = self.orderArr;
            
            vc.orderDicSuccess = self.orderDic;
            
            vc.orderSpphArrSuccess = self.orderSpphArr;
            
            vc.memCardSuccess = self.memberPay;
            
            vc.payedMoneySuccess = self.memberMoney;
            
            vc.cashPaySuccess = self.orderCashAll;
            
            vc.changeMoneySuccess = self.orderCashChange;
            
            vc.orderNo =  [UserModel sharedInstanced].orderNo;
            
            if ([self.index isEqualToString:@"1"]) {
                
                vc.dispatchType = @"会员自提";
                
                [self.navigationController pushViewController:vc animated:YES];
       
            }else if ([self.index isEqualToString:@"2"]){
                
                vc.dispatchType = @"会员配送";
                
                [self.navigationController pushViewController:vc animated:YES];
         
                
                
            }else if ([self.index isEqualToString:@"3"]){
                
                vc.dispatchType = @"门店配送";
                
                [self.navigationController pushViewController:vc animated:YES];
               
            }else{
                
                vc.dispatchType = @"门店自提";
                
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }else{
    
            ShowMessage(responseObject[@"msg"]);
            [UserModel sharedInstanced].token = responseObject[@"token"];
        }
        [self.tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

@end

@implementation PaymentViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    [self NavColor];
}

// 导航颜色
- (void)NavColor{
    
    UINavigationBar * bar = self.navigationController.navigationBar;
    UIImage *bgImage = [UIImage imageWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 64) WihtColor:getColor(navColor) alphe:1.0];
    [bar setBackgroundImage:bgImage forBarMetrics:UIBarMetricsDefault];
    
    
    [bar setShadowImage:[UIImage imageWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0.1) WihtColor:[UIColor blackColor] alphe:1.0]];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"确认订单";
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomView];
}

#pragma Action---


//去掉小数点后面的0
-(NSString*)removeFloatAllZero:(NSString*)string
{
    NSString * testNumber = string;
    NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
    return outNumber;
}

- (void)payMentClick{
    
    if ([self.inputCell.passTextField.text isEqualToString:@""]) {
        ShowMessage(payPasswordNull);

        self.payBtn.enabled = NO;
        return;

    }

    if ([self.cellPayMoney.inputCashField.text isEqualToString:@""]) {
        ShowMessage(@"请输入现金");

        self.payBtn.enabled = NO;
        
        return;

        }

    
//    
//    if ([self.orderCashAll floatValue] + [self.orderCashChange floatValue] < [self.needPayMoney floatValue]) {
//        
//        ShowMessage(@"现金金额不正确");
//        
//        return;
//    }
    
    NSLog(@"111111");
    if ([self.personText isEqualToString:@""]) {
         NSLog(@"222222");
        ShowMessage(@"请输入联系人");
         NSLog(@"333333");
        return;
    }
    if ([self.contactText isEqualToString:@""]) {
        ShowMessage(@"请输入联系方式");
        return;
    }
    if ([self.dispatchText isEqualToString:@""]) {
        ShowMessage(@"请输入地址");
        return;
    }
    
    

    [self getMorderPayCheckData];
   
    DispatchStyleView * dispatchView = [[DispatchStyleView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [dispatchView show];
    
    
    //价钱和销量
    dispatchView.totalPriceLabel.text = [NSString stringWithFormat:@"￥%@",self.orderDic[@"orderXsje"]];
    dispatchView.countLabel.text = [NSString stringWithFormat:@"%@",self.orderDic[@"orderXssl"]];
    
    dispatchView.getMemSelfClick = ^{
        self.disttype = @"mem1";
        self.index = @"1";
    };
    
    ws(dispatchView)
    dispatchView.getMemDispatch = ^{
        self.disttype = @"mem0";
        self.index = @"2";
        self.personText = [UserModel sharedInstanced].personTestStr;
        self.contactText = [UserModel sharedInstanced].contactTestStr;
        self.dispatchText = [UserModel sharedInstanced].adressTestStr;
        self.remarkText = [UserModel sharedInstanced].memDisTestStr;
        

    };
    
    dispatchView.getStoreClick = ^{
        self.disttype = @"org1";
        self.index = @"3";
        self.remarkText = [UserModel sharedInstanced].shopTestStr;
        
    } ;
    
    dispatchView.getStoreSelf = ^{
        self.disttype = @"org0";
        self.index = @"4";
        self.remarkText = [UserModel sharedInstanced].storeTestStr;
    };
    
    dispatchView.getDispatchClick = ^{

        if (self.index) {
            
             [self getConfigSaleDataWithIndex:self.index];
            
        }else{
           
            self.disttype = @"mem1";
           
            [self getConfigSaleDataWithIndex];
        }
        
        
        [weakdispatchView dismiss];
    };
}

#pragma init --

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - height64 - UNIT_HEIGHT(49)) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0.01)];
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0.01)];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.bounces = NO;
    }
    return _tableView;
}

// 底部视图

- (UIView *)bottomView{
    if (!_bottomView) {
        _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tableView.frame), SCREEN_WIDTH, UNIT_HEIGHT(49))];
        _bottomView.backgroundColor = [UIColor whiteColor];
        
        _shopImageview = [UIImageView new];
        _shopImageview.contentMode = UIViewContentModeScaleAspectFit;
        _shopImageview.image = [UIImage imageNamed:@"gouwuche"];
        
        _totalPriceLabel = [[UILabel alloc] init];
        _totalPriceLabel.textColor = getColor(@"EC4350");
        _totalPriceLabel.font = DEF_FontSize_18;
        _totalPriceLabel.text = [NSString stringWithFormat:@"￥%@",self.orderDic[@"orderXsje"]];
     
        
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.font = DEF_FontSize_14;
        _numberLabel.textColor = getColor(@"323232");
        _numberLabel.text = @"销量 :";
        
        _countLabel = [[UILabel alloc] init];
        _countLabel.font =DEF_FontSize_14;
        _countLabel.textColor = getColor(@"323232");
        _countLabel.text = [NSString stringWithFormat:@"%@",self.orderDic[@"orderXssl"]];
        
        _payBtn = [[UIButton alloc] init];
        _payBtn .backgroundColor = getColor(@"EC4350");
        [_payBtn setTitle:@"提交订单" forState:UIControlStateNormal];
        [_payBtn setTitleColor:getColor(@"FFFFFF") forState:UIControlStateNormal];
        [_payBtn addTarget:self action:@selector(payMentClick) forControlEvents:UIControlEventTouchUpInside];
    
        
        [_bottomView sd_addSubviews:@[_shopImageview,_totalPriceLabel,_numberLabel,_countLabel,_payBtn]];
        
        _shopImageview.sd_layout
        .topSpaceToView(_bottomView ,UNIT_HEIGHT(12))
        .leftSpaceToView(_bottomView , UNIT_HEIGHT(16))
        .widthIs(UNIT_WIDTH(30))
        .heightIs(UNIT_HEIGHT(30));
        
        _totalPriceLabel.sd_layout
        .centerYEqualToView(_shopImageview)
        .leftSpaceToView(_shopImageview , UNIT_HEIGHT(6))
        .widthIs(UNIT_WIDTH(100))
        .heightIs(UNIT_HEIGHT(30));
        
        _numberLabel.sd_layout
        .centerYEqualToView(_shopImageview)
        .leftSpaceToView(_totalPriceLabel, UNIT_HEIGHT(6))
        .widthIs(UNIT_WIDTH(50))
        .heightIs(UNIT_HEIGHT(30));
        
        _countLabel.sd_layout
        .centerYEqualToView(_shopImageview)
        .leftSpaceToView(_numberLabel, UNIT_HEIGHT(0))
        .widthIs(UNIT_WIDTH(60))
        .heightIs(UNIT_HEIGHT(30));
        
        [_payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(UNIT_WIDTH(100));
        }];
    }
    return _bottomView;
}

#pragma mark - <UITableViewDelegate , UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        if ([self.passWordAppear isEqualToString:@"1"]) {
            
            return 4;
        }else{
        
        self.textStrPass = @"";
        return 3;

        }
    }else if (section == 1){
    return 1;
    }
    return self.orderArr.count;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 2) {
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, UNIT_HEIGHT(44))];
        whiteView.backgroundColor = getColor(whiteColor);
        
    UILabel * goodNameLabel = [[UILabel alloc] init];
    goodNameLabel.text = @"商品名称";
    goodNameLabel.textColor = getColor(textColor);
    goodNameLabel.font = DEF_FontSize_11;
    
    UILabel * conntLabel = [[UILabel alloc] init];
    conntLabel.textColor = getColor(textColor);
    conntLabel.font = DEF_FontSize_11;
    conntLabel.text = @"数量";
    
    UILabel * moneyLabel = [[UILabel alloc] init];
    moneyLabel.textColor = getColor(textColor);
    moneyLabel.font = DEF_FontSize_11;
    moneyLabel.text = @"金额";
    
    [whiteView sd_addSubviews:@[goodNameLabel,conntLabel,moneyLabel]];
    
    [goodNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(15));
        make.top.mas_equalTo(UNIT_HEIGHT(0));
        make.bottom.mas_equalTo(0);
    }];
    
    [conntLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(UNIT_WIDTH(250));
        make.top.mas_equalTo(UNIT_HEIGHT(0));
        make.bottom.mas_equalTo(0);
    }];
    
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(UNIT_WIDTH(-15));
        make.top.mas_equalTo(UNIT_HEIGHT(0));
        make.bottom.mas_equalTo(0);
    }];
    
    return whiteView;
    }
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
            if (indexPath.row == 3) {
                InputMoneyTableViewCell * cell = [InputMoneyTableViewCell cellForTableView:tableView];
                self.inputCell = cell;
    
                cell.getTextFieldClick = ^(InputMoneyTableViewCell *cell) {
                    self.textStrPass = cell.strPass;
                };
                
                cell.getEyeBtnClick = ^(InputMoneyTableViewCell *cell) {
                    
                    static int i = 0;
                    i ++ ;
                    if (i % 2 == 0) {
                        cell.eyeImageView.image = [UIImage imageNamed:@"yanjing"];
                        NSString *tempPwdStr = cell.passTextField.text;
                        cell.passTextField.text = @"";
                        cell.passTextField.secureTextEntry = NO;
                        cell.passTextField.text = tempPwdStr;
                    }else{
                        cell.eyeImageView.image = [UIImage imageNamed:@"yangjing_guan"];
                        NSString *tempPwdStr = cell.passTextField.text;
                        cell.passTextField.text = @"";
                        cell.passTextField.secureTextEntry = YES;
                        cell.passTextField.text = tempPwdStr;
                    }
                };
                 return cell;
        }
        PaymentTableViewCell * cell = [PaymentTableViewCell cellForTableView:tableView];
        cell.model = self.contentArr[indexPath.row];
        return cell;
    }else if (indexPath.section == 1){
        //根据上面计算会员卡支付金额以及计算还需支付现金以及计算找零
        //余额够的情况
        if (([self.orderDic[@"fCardMoney"] integerValue] - [self.orderDic[@"orderXsje"] integerValue]) > 0) {
            
         PayMoneyWithOutTableViewCell * cell = [PayMoneyWithOutTableViewCell cellForTableView:tableView];
       
            
        cell.payMoneyLabel.text = [NSString stringWithFormat:@"￥%@",self.orderDic[@"orderXsje"]];
    
            cell.memberMoneyLabel.text = [NSString stringWithFormat:@"￥%@",self.orderDic[@"orderXsje"]];
            self.memberPay = self.orderDic[@"orderXsje"];
            
            self.orderCashAll = @"0";
           
            self.orderCashChange = @"0";
            
            self.needPayMoney = @"0";
            
            return cell;
            
        }else{
            //余额不够的情况
            PayMoneyTableViewCell * cell = [PayMoneyTableViewCell cellForTableView:tableView];
            self.cellPayMoney = cell;
            
             cell.payMoneyLabel.text = [NSString stringWithFormat:@"￥%@",self.orderDic[@"orderXsje"]];
            cell.memberMoneyLabel.text =  [NSString stringWithFormat:@"￥%@",self.orderDic[@"fCardMoney"]];
            self.memberPay = self.orderDic[@"fCardMoney"];
            
            
            float money = [self.orderDic[@"orderXsje"] floatValue] - [self.orderDic[@"fCardMoney"] floatValue];
            
            //现金金额
            
            NSString * moneyStr = [NSString stringWithFormat:@"%f",money];
            
            self.needPayMoney = [self removeFloatAllZero:moneyStr];
            
            cell.needPayLabel.text = [NSString stringWithFormat:@"还需支付现金￥%@",self.needPayMoney];
           
    
            cell.getTextFieldClick = ^(PayMoneyTableViewCell *cell) {
            
                //现金总金额
                NSString * str =  [NSString stringWithFormat:@"%f",cell.goodCount];
                
                NSString * str1 = [self removeFloatAllZero:str];
                
                self.orderCashAll = str1;
                
                float goodCount = 0;
                
                if (str.length  > 0) {
                    
                    goodCount = cell.goodCount;
                    
                }
                
                float change = goodCount - money ;
                
                if (change < 0) {
                    
                    change = 0;
                }
                
                NSString * strChange = [NSString stringWithFormat:@"%f",change];
                
                NSString * strChng = [self removeFloatAllZero:strChange];
                
                cell.findMoenyLabel.text = [NSString stringWithFormat:@"找零￥%@",strChng];
                
                self.orderCashChange = strChng;
                
            };
            return cell;
        
        }
    }
    GoodMoneyTableViewCell * cell = [GoodMoneyTableViewCell cellForTableView:tableView];
    
    cell.model = self.orderArr[indexPath.row];
    
    
    //展开
    ws(cell)
    cell.getSpreadClick = ^{
       
        [UIView animateWithDuration:0.5 animations:^{
            
            weakcell.spreadBtn.hidden = YES;
            
            NSIndexPath * indexpath = [self.tableView indexPathForCell:((UITableViewCell*)[weakcell.spreadBtn superview])];
            
            NSLog(@"点击了哪个%@",indexpath);
            //这写个字典存一下我是在哪个地方点击了这个按钮
#warning -------- 这写个字典存一下我是在哪个地方点击了这个按钮
            
            
            
            CardView * cardView = [[CardView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(weakcell.picImageView.frame) + 10 , SCREEN_WIDTH, UNIT_HEIGHT(180)) ];
             [weakcell addSubview:cardView];
            
            //取出商品里的商品编号
            for (PayMentGoodModel *model in self.orderArr) {
                self.strGood = model.spbh;
            }
            
            //取出商品编号里的商品编号
            for (PayMentSpphModel *model in self.orderSpphArr) {
              self.strSpph = model.fSpbh;
            }
            
            //如果商品里的商品编号和商品编号里的商品编号的编号一致,就显示对应的数据
            if ([self.strGood isEqualToString:self.strSpph]) {
                
               
                
                cardView.model = self.orderSpphArr[indexPath.row];
                
            }
        
            ws(cardView)
            
            cardView.getCloseClick = ^{
                //收起
                weakcardView.hidden = YES;
                weakcell.spreadBtn.hidden = NO;
            };
            
            //弹出修改批次批号的view
            cardView.getchangeCardBtnClick = ^{
                [self getSerialNumDataWith:self.strGood];
               
            };
       
        } completion:^(BOOL finished) {
            
        }];
        
    };
   
    return cell;
    }



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 50;
    }else if (indexPath.section == 1){
        if (([self.orderDic[@"fCardMoney"] integerValue] - [self.orderDic[@"orderXsje"] integerValue]) > 0) {
            
       return 100;

    }else{
        return 230;
        }
  }
    return 300;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 2) {
        return UNIT_HEIGHT(44);
    }else if (section == 0){
        return 0;
    }
    return UNIT_HEIGHT(5);
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 1) {
        return UNIT_HEIGHT(5);
    }else{
        return 0;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  
    
}

#pragma mark --- 懒加载
- (NSMutableArray *)contentArr{
    if (!_contentArr) {
        _contentArr = @[@{@"image":@"huiyuanka拷贝",@"content":[NSString stringWithFormat:@"卡号%@",self.orderDic[@"fCardno"]] ,@"price":self.orderDic[@"fName"] }.mutableCopy,
                      @{@"image":@"yue",@"content":@"会员卡余额",@"price":[NSString stringWithFormat:@"￥%@",self.orderDic[@"fCardMoney"]] }.mutableCopy,
                    @{@"image":@"shouji",@"content":@"手机号",@"price":[NSString stringWithFormat:@"%@",self.orderDic[@"fMobiletel"]] }.mutableCopy,
                        ].mutableCopy;
    }
    return _contentArr;
}

- (NSMutableDictionary *)indexHeight{
    
    if (!_indexHeight) {
        _indexHeight = [NSMutableDictionary dictionary];
        
    }
    return _indexHeight;
}

- (NSMutableArray *)changeSpphArr{
    
    if (!_changeSpphArr) {
        
        _changeSpphArr = @[
                           ].mutableCopy;
        
    }
    return _changeSpphArr;
}

@end
